package com.jiulan.hearthearing.ui.cart.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jiulan.hearthearing.R;
import com.jiulan.hearthearing.ui.cart.model.CartModel;
import com.jiulan.hearthearing.ui.cart.util.CartUtil;
import com.shehuan.niv.NiceImageView;

import java.util.List;

public class CartAdapter extends BaseQuickAdapter<CartModel.DataBean.ValidBean, BaseViewHolder> {

    public CartAdapter(List<CartModel.DataBean.ValidBean> data) {
        super(R.layout.item_cart, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CartModel.DataBean.ValidBean item) {
        NiceImageView nivPic = helper.getView(R.id.nivPic);
        Glide.with(mContext).load(item.getProductInfo().getLecturer().getPic()).apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(6))).into(nivPic);
        helper.setText(R.id.tvTitle, item.getProductInfo().getTitle());
        helper.setText(R.id.tvContent, item.getProductInfo().getShort_title());
        helper.setText(R.id.tvAuthor, item.getProductInfo().getLecturer().getName() + "·" + item.getProductInfo().getLecturer().getTitle());
        helper.setText(R.id.tvMoney, "¥" + item.getTruePrice());
        ImageView ivSelect = helper.getView(R.id.ivSelect);
        CartUtil.checkItem(item.isSelect(), ivSelect);
        helper.addOnClickListener(R.id.ivSelect);
        helper.setGone(R.id.tvNoCoupon,true);
        helper.setGone(R.id.rlCoupon,false);
    }
}
